package com.example.android.ui.addHB;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.RequestBody;

public class AddHBPresenter implements AddHBContract.IAddHBPresenter {
    private AddHBContract.IAddHBView addHBView;
    AddHBContract.IAddHBModel addHBModel;
    public AddHBPresenter(AddHBContract.IAddHBView addHBView){
        this.addHBView = addHBView;
        addHBModel = new AddHBModel();
    }

    @Override
    public void addHB(RequestBody body) {
        addHBModel.addHB(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Throwable {
                        addHBView.addHBSuccess(aBoolean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        addHBView.addHBError(throwable);
                    }
                });
    }
}
